import request from "../utils/request";
import fetch from "dva/fetch";

// export const online = `http://39.105.117.74:8085`; //配置线上地址
export const online = "https://nmmwsaas.nmgcyy.com.cn/supervise"
let webUrl;
if (window.location.host.indexOf("localhost") > -1) {
  webUrl = online;
} else {
  webUrl = `${document.location.protocol}//${window.location.host}`;
}
// export const UrlConfig = "http://39.105.117.74:8085";
// export const UrlConfig = "https://nmmwsaas.nmgcyy.com.cn/supervise";
export const UrlConfig = "https://8085.sobeylingyun.com";

export const call = function(url, method = "get", data = {}) {
  url = UrlConfig + url;
  if (method == "get") {
    let urls = "?";
    for (const key in data) {
      if (data.hasOwnProperty(key)) {
        urls = `${urls}${key}=${data[key]}&`;
      }
    }
    url = url + urls;
    return request(url);
  } else if (method == "post") {
    return request(url, {
      method: "post",
      headers: { "Content-Type": "application/json; charset=utf-8" },
      body: JSON.stringify(data)
    });
  }
};

const option = function(data) {
  return {
    method: "post",
    headers: { "Content-Type": "application/json; charset=utf-8" },
    body: JSON.stringify(data)
  };
};
/**
 * 获取全局配置列表
 */
export function getConfig() {
  return call("/fcinformation/AppConfig/getConf", "get", { config_id: 1 });
}

/**
 * 上传base64图片
 */
export function uploadImgBase64(data) {
  return call("/fcinformation/Information/uploadImgBase64", "post", data);
}

/**
 * 敏感词过滤
 */
export function validateSensitive(data) {
  return call("/fcpublic/Sensitivewords/validateSensitive", "post", data);
}

/**
 * 上传服务器图片到oss
 */
export function uploadOssImg(data) {
  return call("/fcpublic/uploads/aliyunossUploadImg", "post", data);
}

/**
 * 视频入库
 */
export function inStock(data) {
  return call("/fcpublic/Megateway/import", "post", data);
}

/**
 * 添加视频到视频组件
 */
export function addToVideo(data) {
  return call("/fcpublic/fcvideo/addVideo", "post", data);
}

/**
 * 提交阿里云转码
 */
export function transcode(data) {
  return call("/fcpublic/Aliyun/transcode", "post", data);
}
